﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using MySql.Data.MySqlClient;
using System.Data;

namespace DAL
{
    public class SOP_BossAlipayReChargeRecordDAL
    {

        #region 添加
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="ProductKey"></param>
        /// <returns>5成功，-5失败，-10000系统错误</returns>
        public int AddBossAlipayReChargeRecord(SOP_BossAlipayReChargeRecord Ent,out int RecordID)
        {
            RecordID = 0;
            using (MySqlConnection conn = DAL.SqlHelper.Settings.GetBrandMySqlConnection(true))
            {
                try
                {
                    MySqlCommand cmd = new MySqlCommand("P_AddBossAlipayReChargeRecord_Arcyun", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@VipUserID_Para", MySqlDbType.VarChar, 11).Value = Ent.VipUserID;//call P_GetNewUserId(10,0)  "userid":
                    cmd.Parameters.Add("@Total_Fee_Para", MySqlDbType.Decimal).Value = Ent.Total_Fee;//call P_GetNewUserId(10,0)  "username10":
                    cmd.Parameters.Add("@Body_Para", MySqlDbType.VarChar, 255).Value = Ent.Body;//商家名称
                    cmd.Parameters.Add("@Buyer_Email_Para", MySqlDbType.VarChar, 56).Value = Ent.Buyer_Email;//商家名称
                    cmd.Parameters.Add("@Buyer_Id_Para", MySqlDbType.VarChar, 56).Value = Ent.Buyer_Id;//邮箱
                    cmd.Parameters.Add("@Is_Success_Para", MySqlDbType.VarChar, 10).Value = Ent.Is_Success;//联系人
                    cmd.Parameters.Add("@Notify_Id_Para", MySqlDbType.VarChar, 100).Value = Ent.Notify_Id;//联系电话
                    cmd.Parameters.Add("@Notify_Time_Para", MySqlDbType.DateTime).Value = Ent.Notify_Time;//开户类型，默认20

                    cmd.Parameters.Add("@Notify_Type_Para", MySqlDbType.VarChar,32).Value = Ent.Notify_Type;//默认为10，5:代表多品牌数据库，10:代表单品牌数据库
                    cmd.Parameters.Add("@Out_Trade_No_Para", MySqlDbType.VarChar, 32).Value = Ent.Out_Trade_No;//商户类型 10：多品牌商户（老的多品牌）；10：单品牌商户；15：多品牌商户（针对单品牌里面创建的多品牌）
                    cmd.Parameters.Add("@Payment_Type_Para", MySqlDbType.VarChar, 10).Value = Ent.Payment_Type;//c831b04d
                    cmd.Parameters.Add("@Subject_Para", MySqlDbType.VarChar, 255).Value = Ent.Subject;//10
                    cmd.Parameters.Add("@Trade_No_Para", MySqlDbType.VarChar, 56).Value = Ent.Trade_No;//当前时间20年后
                    cmd.Parameters.Add("@Trade_Status_Para", MySqlDbType.VarChar, 32).Value = Ent.Trade_Status;//当前时间
                    cmd.Parameters.Add("@Sign_Para", MySqlDbType.VarChar, 56).Value = Ent.Sign;//当前时间
                    cmd.Parameters.Add("@OperatorID_Para", MySqlDbType.VarChar, 11).Value = Ent.OperatorID;//当前时间
                    cmd.Parameters.Add("@TradeType_Para", MySqlDbType.Int32).Value = Ent.TradeType;//专柜数
                    cmd.Parameters.Add("@Status_Para", MySqlDbType.Int32).Value = Ent.Status;//登陆账号 ProductUserName
                    cmd.Parameters.Add("@CheckTime_Para", MySqlDbType.DateTime).Value = Ent.CheckTime;//默认5；5：专柜，10门店，15药店
                    cmd.Parameters.Add("@CheckUserID_Para", MySqlDbType.VarChar, 32).Value = Ent.@CheckUserID;//5
                    cmd.Parameters.Add("@Remark_Para", MySqlDbType.VarChar, 255).Value = Ent.Remark;//5
                    cmd.Parameters.Add("@OperatorCode_Para", MySqlDbType.VarChar, 20).Value = Ent.OperatorCode;//10
                    cmd.Parameters.Add("@OperatorName_Para", MySqlDbType.VarChar, 32).Value = Ent.OperatorName;//5
                    cmd.Parameters.Add("@AddTime_Para", MySqlDbType.DateTime).Value = Ent.AddTime;//默认5；5：专柜，10门店，15药店
                    cmd.Parameters.Add("@CheckUserName_Para", MySqlDbType.VarChar, 32).Value = Ent.CheckUserName;//5

                    cmd.Parameters.Add("@RecordID_Para", MySqlDbType.Int32).Value = 0;
                    cmd.Parameters["@RecordID_Para"].Direction = ParameterDirection.Output;
                    cmd.Parameters.Add("@IsSuccess_Para", MySqlDbType.Int32).Value = 0;
                    cmd.Parameters["@IsSuccess_Para"].Direction = ParameterDirection.Output;
                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }
                    cmd.ExecuteNonQuery();
                    Object ObjRecordID = cmd.Parameters["@RecordID_Para"].Value;
                    RecordID = ObjRecordID == null || ObjRecordID.ToString() == string.Empty ? -5 : (int)ObjRecordID;
                    Object ObjRtID = cmd.Parameters["@IsSuccess_Para"].Value;
                    return ObjRtID == null || ObjRtID.ToString() == string.Empty ? -5 : (int)ObjRtID;

                }
                catch (Exception ex)
                {
                    ActCommon.Log.WriteLog("AddProductKey(date:'" + System.DateTime.Now + "'),error:" + ex.Message, "AddCompany");
#if DEBUG
                    throw ex;
#else
                    return -10000;
#endif
                }
                finally
                {
                    conn.Close();
                }
            }
        }
        #endregion

        #region 修改
        public int UpdateBossAlipayReChargeRecord(SOP_BossAlipayReChargeRecord Ent)
        {
            using (MySqlConnection conn = DAL.SqlHelper.Settings.GetBrandMySqlConnection(true))
            {
                try
                {
                    MySqlCommand cmd = new MySqlCommand("P_UpdateBossAlipayReChargeRecord_Arcyun", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@VipUserID_Para", MySqlDbType.VarChar, 11).Value = Ent.VipUserID;//商家名称
                    cmd.Parameters.Add("@Total_Fee_Para", MySqlDbType.Decimal).Value = Ent.Total_Fee;//call P_GetNewUserId(10,0)  "username10":
                    cmd.Parameters.Add("@Body_Para", MySqlDbType.VarChar, 255).Value = Ent.Body;//商家名称
                    cmd.Parameters.Add("@Buyer_Email_Para", MySqlDbType.VarChar, 56).Value = Ent.Buyer_Email;//商家名称
                    cmd.Parameters.Add("@Buyer_Id_Para", MySqlDbType.VarChar, 56).Value = Ent.Buyer_Id;//邮箱
                    cmd.Parameters.Add("@Is_Success_Para", MySqlDbType.VarChar, 10).Value = Ent.Is_Success;//联系人
                    cmd.Parameters.Add("@Notify_Id_Para", MySqlDbType.VarChar, 100).Value = Ent.Notify_Id;//联系电话
                    cmd.Parameters.Add("@Notify_Time_Para", MySqlDbType.DateTime).Value = Ent.Notify_Time;//开户类型，默认20
                    cmd.Parameters.Add("@Notify_Type_Para", MySqlDbType.VarChar, 32).Value = Ent.Notify_Type;//默认为10，5:代表多品牌数据库，10:代表单品牌数据库
                    cmd.Parameters.Add("@Out_Trade_No_Para", MySqlDbType.VarChar, 32).Value = Ent.Out_Trade_No;//商户类型 10：多品牌商户（老的多品牌）；10：单品牌商户；15：多品牌商户（针对单品牌里面创建的多品牌）
                    cmd.Parameters.Add("@Payment_Type_Para", MySqlDbType.VarChar, 10).Value = Ent.Payment_Type;//c831b04d
                    cmd.Parameters.Add("@Subject_Para", MySqlDbType.VarChar, 255).Value = Ent.Subject;//10
                    cmd.Parameters.Add("@Trade_No_Para", MySqlDbType.VarChar, 56).Value = Ent.Trade_No;//当前时间20年后
                    cmd.Parameters.Add("@Trade_Status_Para", MySqlDbType.VarChar, 32).Value = Ent.Trade_Status;//当前时间
                    cmd.Parameters.Add("@Sign_Para", MySqlDbType.VarChar, 56).Value = Ent.Sign;//当前时间
                    cmd.Parameters.Add("@TradeType_Para", MySqlDbType.Int32).Value = Ent.TradeType;//专柜数
                    cmd.Parameters.Add("@Status_Para", MySqlDbType.Int32).Value = Ent.Status;//登陆账号 ProductUserName

                    cmd.Parameters.Add("@IsSuccess_Para", MySqlDbType.Int32).Value = 0;
                    cmd.Parameters["@IsSuccess_Para"].Direction = ParameterDirection.Output;
                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }
                    cmd.ExecuteNonQuery();
                    Object ObjRtID = cmd.Parameters["@IsSuccess_Para"].Value;
                    return ObjRtID == null || ObjRtID.ToString() == string.Empty ? -5 : (int)ObjRtID;

                }
                catch (Exception ex)
                {
                    ActCommon.Log.WriteLog("AddProductKey(date:'" + System.DateTime.Now + "'),error:" + ex.Message, "AddCompany");
#if DEBUG
                    throw ex;
#else
                    return -10000;
#endif
                }
                finally
                {
                    conn.Close();
                }
            }
        }
        #endregion
    }
}
